home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Franz PD / Franz PD Disk #009 (19xx)(Amiga User Group Deutschland e.V.).zip / Franz PD Disk #009 (19xx)(Amiga User Group Deutschland e.V.).adf / HeliosMouse / Helios-Handler.c < prev    next >
C/C++ Source or Header  |  1986-10-22  |  4KB  |  133 lines

  1. /*
  2.  *  Helio-Handler.c     Input Handler for HeliosMouse.  Helios-handler
  3.  *                      calls ActivateWindow() whenever the mouse moves
  4.  *                      over a new window.
  5.  *
  6.  *              Copyright (c) 1987 by Davide P. Cervone
  7.  *  You may use this code provided this copyright notice is left intact.
  8.  */
  9.  
  10. #include <exec/types.h>
  11. #include <devices/inputevent.h>
  12. #include <intuition/intuitionbase.h>
  13.  
  14. static char *version = "Helios-Handler v1.0 (June 1987)";
  15. static char *author  = "Copyright (c) 1987 by Davide P. Cervone";
  16.  
  17. extern struct Layer *WhichLayer();
  18. extern void myHandlerStub();
  19.  
  20. /*
  21.  *  The window associated with a given Layer structure.
  22.  */
  23. #define WINDOW(layer)   ((struct Window *)((layer)->Window))
  24.  
  25. /*
  26.  *  The top line of a screen (in INTERLACED lines)
  27.  */
  28. #define SCREENTOP\
  29.    (theScreen->TopEdge << ((theScreen->ViewPort.Modes & LACE)? 0: 1))
  30.  
  31.  
  32. struct IntuitionBase *IntuitionBase = NULL;
  33. struct LayersBase    *LayersBase    = NULL;
  34. struct SysBase       *SysBase       = NULL;
  35.  
  36. /*
  37.  *  Setup()
  38.  *
  39.  *  HeliosMouse calls LoadSeg() to get this handler into memory.  The segment
  40.  *  that it gets points to this routine.  HeliosMouse calls Setup() and 
  41.  *  passes the IntuitionBase, LayersBase and SysBase pointers that it
  42.  *  has initialized (with OpenLibrary()).  Setup returns a pointer to
  43.  *  the actual input handler, which HeliosMouse installs.
  44.  */
  45.  
  46. long Setup(Ibase,Lbase,Sbase)
  47. struct IntuitionBase *Ibase;
  48. struct LayersBase *Lbase;
  49. struct SysBase *Sbase;
  50. {
  51.    IntuitionBase = Ibase;
  52.    LayersBase = Lbase;
  53.    SysBase = Sbase;
  54.    return((long) &myHandlerStub);
  55. }
  56.  
  57.  
  58. /*
  59.  *  myHandler()
  60.  *
  61.  *  This is the input handler.  Whenever a mouse move or a keyboard event
  62.  *  occurs, we check to see if the mouse is over an inactive window, and
  63.  *  if so, we activate that window.
  64.  *
  65.  *  To do this, we get the current absolute Y position of the mouse and
  66.  *  look through the Intuition screens for the first one that is closer
  67.  *  to the top of the View than the mouse is (i.e., the first one that is
  68.  *  high enough to be under the mouse).  Note that we must convert non-
  69.  *  interlace screen coordinates to interlaces ones in order to be able
  70.  *  to compare them to the mouse position (the SCREENTOP macro does this).
  71.  *  If no screen is found (this should never happen, but just in case), then 
  72.  *  just use the currently active one.
  73.  *
  74.  *  From the selected screen we get the mouse x and y position (if it's a 
  75.  *  mouse move, we add the event offsets to find the new mouse position).  
  76.  *  Using these, we call WhichLayer(), which tells us which Layer within 
  77.  *  that screen the mouse was pointing at.  If that layer has a window and 
  78.  *  that window is not currently the active window, we activate it.
  79.  *
  80.  *  When we're all through looking at events, we pass the list on, so that
  81.  *  Intuition (and any other handlers) can do their things.
  82.  *
  83.  *  Compile this section with -dKEY_ONLY to have windows activate only when 
  84.  *  a key is pressed (not when the mouse moves over an inactive one).
  85.  */
  86.  
  87. struct InputEvent *myHandler(EventList,data)
  88. struct InputEvent *EventList;
  89. APTR data;
  90. {
  91.    register struct InputEvent *theEvent = EventList;
  92.    register struct Layer  *theLayer;
  93.    register struct Window *theWindow;
  94.    register struct Screen *theScreen;
  95.    register long x,y;
  96.  
  97.    Forbid();
  98.    while(theEvent)
  99.    {
  100.       if (
  101.           #ifndef KEY_ONLY
  102.             (theEvent->ie_Class == IECLASS_RAWMOUSE &&
  103.             (theEvent->ie_X != 0 || theEvent->ie_Y != 0)) ||
  104.           #endif
  105.             (theEvent->ie_Class == IECLASS_RAWKEY)
  106.          )
  107.       {
  108.          y = IntuitionBase->MouseY;
  109.          theScreen = IntuitionBase->FirstScreen;
  110.          while (theScreen && y < SCREENTOP) theScreen = theScreen->NextScreen;
  111.          if (theScreen == NULL) theScreen = IntuitionBase->ActiveScreen;
  112.  
  113.          x = theScreen->MouseX;
  114.          y = theScreen->MouseY;
  115.          #ifndef KEY_ONLY
  116.             if (theEvent->ie_Class == IECLASS_RAWMOUSE)
  117.             {
  118.                x += theEvent->ie_X;
  119.                y += theEvent->ie_Y;
  120.             }
  121.          #endif
  122.  
  123.          theLayer = WhichLayer(&(theScreen->LayerInfo),x,y);
  124.          if (theLayer && (theWindow = WINDOW(theLayer)))
  125.             if (theWindow != IntuitionBase->ActiveWindow)
  126.                ActivateWindow(theWindow);
  127.       }
  128.       theEvent = theEvent->ie_NextEvent;
  129.    }
  130.    Permit();
  131.    return(EventList);
  132. }
  133.